<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    class Dep {
        subs = []
        constructor() {

        }
        addSub(sub) {
            if (sub && sub.update) {
                this.subs.push(sub)
            }
        }
        notify() {
            this.subs.forEach(sub => {
                sub.update()
            })
        }
    }
    class Watcher {
        update() {
            console.log('xxxx')
        }
    }
    let dep=new Dep();
    let watcher1=new Watcher();
    let watcher2=new Watcher();
    dep.addSub(watcher1);
    dep.addSub(watcher2);
    dep.notify()
</script>

</html>